﻿
(function (global) {
    var app = angular.module("AdminConsoleApp", []);

    app.controller("Home", function ($scope, $http) {

        function build(page) {
            return 'ui/view/' + page + '.html';
        }

        function getPage(modules) {
            if (global.location.hash.length) {
                var page = global.location.hash.substr(2),
                    valid = false;
                modules.forEach(function (it) {
                    if (it.name === page) {
                        valid = true;
                    }
                });
                if (valid) {
                    return page;
                }
            }
            return 'request';
        }

        $scope.current = null;

        //$scope.active = function (page) {
        //    if ($scope.current.indexOf(page) !== -1) {
        //        return 'active';
        //    } else {
        //        return '';
        //    }
        //};

        $scope.navigate = function (page) {
            $scope.current = build(page);
        };

        $http.get('bc/module.json').success(function (response) {
            $scope.data = response;
            $scope.current = build(getPage(response.modules));
        });
    });

    // expose
    global.app = app;

}(window));